package com.jia.controller;

import com.jia.dto.admin.LoginAdminDto;
import com.jia.entity.Admin;
import com.jia.service.AdminService;

import com.jia.vo.Result;
import com.jia.vo.ResultCodeEnum;
import com.jia.vo.admin.UserInfo;
import com.jia.vo.admin.ValidateCodeVo;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@RequestMapping("/api")
public class AdminController {

    @Autowired
    private AdminService adminService;





    /**
     * 登录
     * @param loginAdminDto
     * @return
     */
    @PostMapping("/login")
    public Result<Map<String, Object>> mapResult(@RequestBody LoginAdminDto loginAdminDto){
        Map<String, Object> login = this.adminService.login(loginAdminDto);
        return Result.build(login, ResultCodeEnum.SUCCESS);
    }

    /**
     * 获取用户信息
     * @param token
     * @return
     */
    @GetMapping("userinfo")
    public Result<UserInfo> userInfoResult(@RequestHeader("token") String token){
        UserInfo userInfo = this.adminService.getUserInfo(token);
        return Result.build(userInfo, ResultCodeEnum.SUCCESS);
    }

    /**
     * 获取图片验证码接口
     * 封装一个验证码VO类
     * @Schema(description = "验证码key")
     * private String codeKey ;        // 验证码的key
     * @Schema(description = "验证码value")
     * private String codeValue ;      // 图片验证码对应的字符串数据
     * @return
     */
    @GetMapping("/validateCode")
    @Schema(description = "获取图片验证码接口")
    public Result<ValidateCodeVo> getValidateCode(){
        ValidateCodeVo validateCodeVo = adminService.getValidateCode();
        return Result.build(validateCodeVo, ResultCodeEnum.SUCCESS);
    }



}
